#!/bin/bash

BASEDIR="$(cd "$(dirname "$0")"; pwd)"
export vblank_mode=0


#export DISPLAY=:0.0

cd $BASEDIR/bin

# its output info may be contains "ATTENTION" in std.err as below:
# ATTENTION: default value of option vblank_mode overridden by environment
#
# so discard "ATTENTION" from output, only remain "COUNT" in std.err.

tname=$(echo $@ | awk '{print $2}')
outlog="output-$tname-$$.log"

./GPU-perf $@ > $outlog 2>&1

ret=$?
if [ $ret != "0" ]; then
    echo "run fail, ret=<$ret>"
    exit $ret
fi

cat $outlog | grep COUNT >&2
keywords="Name           | Type            | Weight   | Fps       |  Result"
state=$(grep -A 1 "$keywords" $outlog | tail -n 1 | awk '{print $NF}')
if [ "$state" != "success" ]; then
    echo "selfcheck error: state=<$state>" 1>&2
    exit 1
fi
rm -f $outlog
exit 0
